﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Conv
{
    public class Neuron
    {
        public double Sigma;
        public Func<double, double> ActivationFunc { get; set; }
        public Func<double, double> ActivationFuncDerivative { get; set; }

        public List<Connection> Inputs { get; set; }
        //List<Connection> Outputs { get; set; }

        public double State { get; set; }//get: return ActivationFunc(sum)
        public double SumInput;
        private const double Etta = 0.3;
        public void Process()
        {
            SumInput = 0;
            foreach (var conn in Inputs)
            {
                SumInput += conn.ForwardAmmount;//biass is also in Inputs
            }
            
            State = ActivationFunc(SumInput);// may be move to get
        }
        public Neuron()
        {
            Sigma = 0;
            Inputs = new List<Connection>();
            //Outputs = new List<Connection>();
        }

        public Neuron(double state)//this constructor for input layer
        {
            Sigma = 0;
            State = state;
        }
        public void BackPropogate()
        {
            Sigma = Sigma*ActivationFuncDerivative(SumInput);//here always zero, cause SumInput is very big(absolute) value, like -81.5
            foreach (Connection connection in Inputs)
            {
                connection.From.Sigma += this.Sigma*connection.Weight.Value;
            }
        }
        public void UpdateWeight()
        {
            foreach (Connection connection in Inputs)
            {
                connection.Weight.Value += Etta*connection.From.Sigma*connection.To.State;
            }
            Sigma = 0;
        }
    }
}